package com.ihcy.beancopy.service.impl;

import com.ihcy.beancopy.dto.OriginClass;
import com.ihcy.beancopy.dto.OriginOrder;
import com.ihcy.beancopy.dto.TargetClass;
import com.ihcy.beancopy.dto.TargetOrder;
import com.ihcy.beancopy.service.IGeneratorDataService;
import com.ihcy.beancopy.service.IOrikaService;
import ma.glasnost.orika.MapperFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrikaServiceImpl implements IOrikaService {

    @Autowired
    private MapperFactory mapperFactory;

    @Autowired
    private IGeneratorDataService generatorDataService;

    @Override
    public List<TargetOrder> getOrdersFromOrigin() {
        List<OriginOrder> originOrders = generatorDataService.getOriginOrders();
        List<TargetOrder> targetOrders = mapperFactory.getMapperFacade().mapAsList(originOrders,TargetOrder.class);
        System.out.println(generatorDataService.test(originOrders,targetOrders));
        return targetOrders;
    }

    @Override
    public List<TargetClass> getClassesFromOrigin() {
        List<OriginClass> originClasses = generatorDataService.getOriginClasses();
        List<TargetClass> targetClasses = mapperFactory.getMapperFacade()
                .mapAsList(originClasses,TargetClass.class);
        System.out.println(generatorDataService.test(originClasses,targetClasses));
        return targetClasses;
    }
}
